package com;

import com.sun.org.apache.xerces.internal.impl.xpath.XPath;
import util.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@WebServlet(value = "/DeleteCourse")
public class DeleteCourse extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         response.setContentType("text/html;charset=UTF-8");
         doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");

        Connection con=null;
        PreparedStatement psm=null;
       // ResultSet rs=null;
        //int c_id= Integer.parseInt(getInitParameter("c_id"));
        //int c_id= Integer.parseInt(request.getParameter("c_id"));
        String c_id=request.getParameter("c_id");
        System.out.println(c_id);
        try {
        con= JdbcUtil.getConnection();
        psm=con.prepareStatement("DELETE FROM course WHERE c_id="+c_id);

        psm.execute();

        } catch (SQLException e) {
            e.printStackTrace();
        }
        request.getRequestDispatcher("/InsertCourse").forward(request,response);
    }
}
